

function setProvince()
{
	Ts_areaInfo.getAreaClassByUpId('000000000000000',function(data){
		DWRUtil.removeAllOptions('province');
		DWRUtil.addOptions('province',{'':'请选择'});
		DWRUtil.addOptions('province',data);
	})
}
function setCitys(prov)
{
   var provence=prov;
	 Ts_areaInfo.getAreaClassByUpId(provence,function(data){
		DWRUtil.removeAllOptions('eparchy_code');
		DWRUtil.addOptions('eparchy_code',{'':'请选择'});
		DWRUtil.addOptions('eparchy_code',data);
	});
}

function setAreas(city_id){
	Ts_areaInfo.getAreaClassByUpId(city_id,function(data){
	 	DWRUtil.removeAllOptions('city_code');
     	DWRUtil.addOptions('city_code',{'':'请选择'});
	 	DWRUtil.addOptions('city_code',data);
	});
}





function setOneClass(val){
	Ts_categoryInfo.getCatClassByUpId("000000000000000",val,setSort1);
}
function setSort1(map_data)
{
	var factory = $("sort1");
	DWRUtil.removeAllOptions("sort1");
	DWRUtil.addOptions('sort1',{'':'请选择'});
	DWRUtil.addOptions("sort1",map_data);
}


  
  var type = "1";
// 设置二级分类
function setSecondClass(val) {
	var up_class_id = val; 
 
	Ts_categoryInfo.getCatClassByUpId(up_class_id, type, setSort2);
}
function setSort2(map_data) {
	DWRUtil.removeAllOptions("sort2");
	DWRUtil.addOptions("sort2", {'':'请选择'});
	DWRUtil.addOptions("sort2", map_data);
	//$("sort3").style.display = "none";
	var item = $("sort2").length;

}
// 设置三级分类
function setTherdClass(val) {
	var up_class_id = val;
	Ts_categoryInfo.getCatClassByUpId(up_class_id, type, setSort3);
}
function setSort3(map_data) {
	if (map_data != null) {
		DWRUtil.removeAllOptions("sort3");
		DWRUtil.addOptions("sort3", {'':'请选择'});
		DWRUtil.addOptions("sort3", map_data);
	}
}
 
function setTypeName1(obj){
	  var idx = obj.value;
		$("class_id3").value="";
		$("class_id2").value="";
		$("class_id1").value=idx;
		//Ts_categoryInfo.getCatNameById(idx,setClassName1);
		//$("class_name").value=DWRUtil.getText(obj.name);
		//$("count").value=obj.name;
}
function setClassName1(val) {
	$("name3").innerHTML = '';
	$("name2").innerHTML = '';
	$("name1").innerHTML = val;
	$("name0").innerHTML = '';
}

function setTypeName2(obj){
	  var idx = obj.value;
	  $("class_id3").value="";
		$("class_id2").value=idx;
		//Ts_categoryInfo.getCatNameById(idx,setClassName2);
		//$("class_name").value=DWRUtil.getText(obj.name);
		//$("count").value=obj.name;
}
function setClassName2(val) {
	$("name3").innerHTML = '';
	$("name2").innerHTML = " > "+val;
}
function setTypeName3(obj){
	  var idx = obj.value;
		$("class_id3").value=idx;
		//Ts_categoryInfo.getCatNameById(idx,setClassName3);
		//$("class_name").value=DWRUtil.getText(obj.name);
		//$("count").value=obj.name;
}
function setClassName3(val) {
	$("name3").innerHTML = " > "+val;
}

function ChangeClassStyle(){
	document.getElementById("class_attr").value = "";
	document.getElementById("flag_code").value = "1";
	document.getElementById("classId1").style.display="none";
	document.getElementById("classId2").style.display="";
}

 
 //验证只能输入数字和小数点
function clearNoNum(obj){
	//先把非数字的都替换掉，除了数字和.
	obj.value = obj.value.replace(/[^\d.]/g,"");
	//必须保证第一个为数字而不是.
	obj.value = obj.value.replace(/^\./g,"");
	//保证只有出现一个.而没有多个.
	obj.value = obj.value.replace(/\.{2,}/g,".");
	//保证.只出现一次，而不能出现两次以上
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}
// 检测是否为合法数据
function isNum(str) {
	return (str.search(/^\d+(\.\d+)?$/) != -1);
}
function trim(str){
    return str.replace(/(^\s*)|(\s*$)/g,"");
  }//去掉空格


//========================提交验证========================
function  submitForm()
{


		if(document.getElementById('user_name') != null) {
		if(document.getElementById('user_name').value==""){

				alert('请输入用户名！');

				document.getElementById('user_name').focus();

				return false;

			}
	
		if(document.getElementById('passwd').value==""){

				alert('请输入密码！');

				document.getElementById('passwd').focus();

				return false;

			}
			
			}

	 var cust_aim = document.addForm.cust_name.value;
	  if(null == cust_aim || cust_aim == "")
	  {
	  	alert("公司名称不能为空!");
	  	document.getElementById("cust_name").focus();
	  	return false;
	  }
	 

	  var a = document.addForm.company_supply.value;
	  var b = document.addForm.company_stock.value;
		var a_b = a+b;
	  if(null == a_b || a_b == ""){
	  	alert("请填写您选中的企业类别！");
	  	document.getElementById("company_stock").focus();
	  	return false;	
	  }
	  
	  var types = document.addForm.company_type.value;
	  if(null == types || types == "请选择")
	  {
	  	alert("请选择企业类型!");
	  	document.getElementById("company_type").focus();
	  	return false;
	  }
	  
	  

	 

	  
	   var enterprise_scope = document.addForm.company_key.value;
	  if(null == enterprise_scope || enterprise_scope == "")
	  {
	  	alert("公司关健词不能为空!");
	  	document.getElementById("company_key").focus();
	  	return false;
	  }
	  var enterprise_size_code = document.addForm.main_product.value;
	  if(null == enterprise_size_code || enterprise_size_code == "")
	  {
	  	alert("公司经营范围不能为空!");
	  	document.getElementById("main_product").focus();
	  	return false;
	  }
	  //分类拼串
		var class_attr_str = "";
		if(document.getElementById("sort1").value!=""){
			class_attr_str += document.getElementById("sort1").value + "|";
			if(document.getElementById("sort2").value!=""){
				class_attr_str += document.getElementById("sort2").value + "|";
				if(document.getElementById("sort3").value!=""){
					class_attr_str += document.getElementById("sort3").value + "|";
				}
			}
		
		}
	  if(class_attr_str==""){
			document.getElementById("class_attr").value = document.getElementById("class_attr_bak").value;
		}else{
			document.getElementById("class_attr").value = class_attr_str;
		}	
		if(document.getElementById("class_attr").value == ""){
				alert("请选择企业分类！");
				document.getElementById("sort1").focus();
				return false;
		}
	  //地区拼串
		var area_attr_str = "";
		if(document.getElementById("province").value!=""){
			area_attr_str += document.getElementById("province").value+"|";
			if(document.getElementById("eparchy_code").value!=""){
				area_attr_str += document.getElementById("eparchy_code").value+"|";
				if(document.getElementById("city_code").value!=""){
					area_attr_str += document.getElementById("city_code").value+"|";
				}
			}
		}
		if(area_attr_str==""){
			document.getElementById("area_attr").value = document.getElementById("area_attr_bak").value;
		}else{
			document.getElementById("area_attr").value = area_attr_str;
		}	
	  var province = document.addForm.area_attr.value;
	  if(null == province || province == "")
	  {
	  	alert("公司所在地不能为空!");
			document.getElementById("province").focus();
	  	return false;
	  }
	  	  	  	  	  	  	  
	var editor_data = CKEDITOR.instances.company_desc.getData();
	
		if(editor_data.length==0){
			alert( "请填写产品的公司简介！" );
			CKEDITOR.instances.company_desc.focus();
			return false;
		}
		//真实姓名不能为空
	  var realname = document.addForm.contact_name.value;
	  if(null == realname || realname == "")
	  {
	  	alert("联系人真实姓名不能为空!");
	  	document.addForm.contact_name.focus();
	  	return false;
	  }
	  var phone = document.addForm.contact_cellphone.value;
	  var myreg1=/^(13\d|15[123456789])\d{5}(\d{3}|\*{3})$/;
	  if(null == phone || phone == "")
	  {
	  	alert("手机号码不能为空!");
	  	document.getElementById("contact_cellphone").focus();
	  	return false;
	  }
	  /**
	  else if(!myreg1.test(phone)){
		   alert("请输入有效的手机号码！");
		   document.getElementById("contact_cellphone").focus();
		   return false;
		}
		**/
	  var job = document.addForm.contact_job.value;
	  if(null == job || job == "")
	  {
	  	alert("职位不能为空!");
	  	document.getElementById("contact_job").focus();
	  	return false;
	   }
	    //把传真号码和区号拼接在一起
	   var group_contact_phone = document.addForm.phone.value;
	  var myreg2 =/^[0][1-9]{2,3}-[0-9]{5,8}$/;
	  if(null == group_contact_phone  )
	  {
	  	alert("固定电话不能为空!");
	  	document.getElementById("phone").focus();
	  	return false;
	  }
	  /**
	  else if(!myreg2.test(group_contact_phone)){
		   alert("请输入有效的固定电话号码！如0551-5310137");
		   document.getElementById("phone").focus();
		   return false;
		}
	**/
	  var email = document.addForm.email.value;
	  var chemEmails=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	
	  if(null == email || email == "")
	  {
	  	alert("邮箱不能为空!");
	  	document.getElementById("email").focus();
	  	return false;
	  }else if (!chemEmails.test(email)){
			alert("Email的格式不正确");
			document.getElementById("email").focus();
			return false;
	  }
	  var company_address = document.addForm.business_addr.value;
	  if(null == company_address || company_address == "")
	  {
	  	alert("经营地址不能为空!");
	  	document.getElementById("business_addr").focus();
	  	return false;
	  }

		
	  
	  //提交时把企业类型拼串
	  document.getElementById("client_status").value = "";
	   
	  for (var i=1;i<=5;i++){
			if(document.getElementById("client_status"+i).checked==true){
				document.getElementById("client_status").value += document.getElementById("client_status"+i).value + "|" ;
				
			}
	  }

	
	  //获取公司经营范围需要过来html代码的控件
	  document.getElementById("main_product").value = document.getElementById("main_product").value.replace(/<\/?[^>]+>/g,""); //去除HTML tag
      document.getElementById("main_product").value = document.getElementById("main_product").value.replace(/[ | ]*\n/g,"\n"); //去除行尾空白
      document.getElementById("main_product").value = document.getElementById("main_product").value.replace(/\n[\s| | ]*\r/g,"\n"); //去除多余空行
	  
		if(document.getElementById('user_class').value==""){

				alert('请选择会员级别！');

				document.getElementById('user_class').focus();

				return false;

			}		
		document.getElementById('cust_class').value = document.getElementById('user_class').value;	   
		
	  document.addForm.submit();

}



//========================用户名验证start ===========================







function ifCheck(){
	
	if(document.getElementById("client_status5").checked == true){
		
		document.getElementById("client_status1").disabled=true;
		document.getElementById("client_status2").disabled=true;
		document.getElementById("client_status3").disabled=true;
		document.getElementById("client_status4").disabled=true;
	}else {
		
		document.getElementById("client_status1").disabled=false;
		document.getElementById("client_status2").disabled=false;
		document.getElementById("client_status3").disabled=false;
		document.getElementById("client_status4").disabled=false;
	}
}



//验证主营方向
function showSpan(val){
	if(val==1){
		document.getElementById('xiaoshou').style.display='block';
		document.getElementById('caigou').style.display='none';
	}
	if(val==0){
		document.getElementById('xiaoshou').style.display='none';
		document.getElementById('caigou').style.display='block';
	}
	if(val==2){
		document.getElementById('xiaoshou').style.display='block';
		document.getElementById('caigou').style.display='block';
	}
}




function choseForm(val)
{
	if(val == "custButton"){
	document.getElementById('custInfo').style.display='';
	document.getElementById('userInfo').style.display='none';
	document.getElementById('levelInfo').style.display='none';
	}
	if(val == "userButton"){
	document.getElementById('custInfo').style.display='none';
	document.getElementById('userInfo').style.display='';
	document.getElementById('levelInfo').style.display='none';
	}
	if(val == "levelButton"){
	document.getElementById('custInfo').style.display='none';
	document.getElementById('userInfo').style.display='none';
	document.getElementById('levelInfo').style.display='';
	}	
}

 //-----------------------------


function ChangeOrg(){
	document.getElementById("org1").style.display = "none";
	document.getElementById("org2").style.display = "inline";
	//document.getElementById("org_id").value = "";
}
